import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * This class it's a structure that can be touched by a certain time. It'll disapeair after it's touched.
 * 
 * @author Manuel Nava
 * @version 1.0
 */
public class Cloud extends Structure
{
    
    private boolean fall;
    private int contDis;
    
    /**
     * Constructor for the class cloud. It set two variables to their initial state; the counter of the time of 
     * cloud and the boolean that indicates if it has benn touched by the player.
       */
    public Cloud()
    {
        fall=false;
        contDis=0;
    }
    
    
    /**
     * The act in this actor calls the method move and checks if the cloud has benn touched by the player and
     * if it has been touched , disapears the cloud or decrements the time it will be in the world.
       */
    public void act() 
    {
        move();
        if(isTouching(Player.class)) fall=true;
        if(fall==true)
        {
           contDis++;
           (this.getImage()).setTransparency(100-contDis);
        }
        if(contDis==100)
           disapear();
        
    }    
    
    /**
     * This method disapears the cloud from the world using the method getWorld and the method removeObject from
     * the class World.
       */
    public void disapear()
    {
        getWorld().removeObject(this);
    }
    
    /**
     * This method move the cloud in the scenario.
       */
    public void move()
    {
        if(((CaveWorld)(getWorld())).getCont()>0)
        {
        if(Greenfoot.isKeyDown("left")&&((CaveWorld)(getWorld())).getMove()==true)
            setLocation(getX()+5,getY());
        if(Greenfoot.isKeyDown("right")&&((CaveWorld)(getWorld())).getMove()==true)
            setLocation(getX()-5,getY());
        }
    }
}
